Skip to content

run python script supports debugging, code bundling, output dir#789

Merged
cosmicBboy merged 7 commits intomainfrom
nielsb/run-python-script-bundle
Mar 16, 2026
Merged

run python script supports debugging, code bundling, output dir#789
cosmicBboy merged 7 commits intomainfrom
nielsb/run-python-script-bundle

Conversation

@cosmicBboy
Copy link
Contributor

This pull request introduces support for running plain Python scripts as Flyte tasks without pickling, by bundling the script and using a new ScriptTaskResolver. It also adds a new copy style (python_script) for code bundles, updates the task and environment APIs to support custom resolvers, and improves the developer experience for remote script execution and debugging. Additional minor changes update dependencies and resource specifications in example files.

Python script task support and code bundling:

  • Added ScriptTaskResolver (src/flyte/_internal/resolvers/script.py) to enable bundling and execution of plain Python scripts as Flyte tasks, avoiding pickling and enabling proper remote debugging.
  • Updated run_python_script (src/flyte/_run_python_script.py) to use the new resolver, bundle scripts with the new python_script copy style, and support VS Code debugging. [1] [2] [3] [4]
  • Introduced build_code_bundle_from_relative_paths and added "python_script" to the CopyFiles literal for selective script bundling. [1] [2]
  • Modified _Runner and remote/hybrid run logic to support the new copy style and script bundling parameters. [1] [2] [3] [4] [5]

Task and environment API enhancements:

  • Added task_resolver argument to TaskEnvironment.task and AsyncFunctionTaskTemplate, and ensured it is used during serialization and container argument construction. [1] [2] [3] [4] [5]

Developer experience and examples:

  • Added a new hello.py script example demonstrating running a plain Python script with Flyte.
  • Updated example resource specifications and dependency versions for better compatibility and GPU support. [1] [2] [3]
  • Added more arguments to VS Code debug launch configuration for improved debugging.

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
@dataclass
class PythonScriptOutput:
exit_code: int
stdout: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we should capture the stdout, this is already in the logs. This can be a lot!

Copy link
Contributor Author

@cosmicBboy cosmicBboy Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note here that I'm only getting the last 1000 characters: https://github.com/flyteorg/flyte-sdk/pull/789/changes#diff-bc180013a121c671af8420075855a9a12efdcd6a01b24e90c07a6322a09001ceR75-R76

This is still useful for local debugging... user (or agent) gets stderr and stdout in the CLI, we have to think LLM-first!

class PythonScriptOutput:
exit_code: int
stdout: str
stderr: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for stderr

Copy link
Contributor Author

@cosmicBboy cosmicBboy Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note here that I'm only getting the last 1000 characters: https://github.com/flyteorg/flyte-sdk/pull/789/changes#diff-bc180013a121c671af8420075855a9a12efdcd6a01b24e90c07a6322a09001ceR75-R76

This is still useful for local debugging... user (or agent) gets stderr and stdout in the CLI, we have to think LLM-first!

__all__ = [
"CopyFiles",
"build_code_bundle",
"build_code_bundle_from_relative_paths",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this an existing function, is it used for apps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@kumare3
Copy link
Contributor

kumare3 commented Mar 13, 2026

I think we should also add support for additional files regex (as a follow up us ok), so i like the include files thing

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
@cosmicBboy
Copy link
Contributor Author

cosmicBboy commented Mar 13, 2026

I think we should also add support for additional files regex (as a follow up us ok), so i like the include files thing

yep, gonna do that in a separate PR

}
return PythonScriptOutput(
exit_code=result.returncode,
stdout=result.stdout[-1000:],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know if this is ok, this will still blow up memory i feel. this will buffer everything in memory

kumare3
kumare3 previously approved these changes Mar 14, 2026
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
@cosmicBboy cosmicBboy merged commit 0c2eec5 into main Mar 16, 2026
29 checks passed
@cosmicBboy cosmicBboy deleted the nielsb/run-python-script-bundle branch March 16, 2026 03:47
from ._ignore import Ignore, IgnoreGroup, StandardIgnore

CopyFiles = Literal["loaded_modules", "all", "none"]
CopyFiles = Literal["loaded_modules", "all", "none", "custom"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow this... what does this do? Are we adding this to the public API now? how will users specify this on the command line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants